package ControllerLayer;
import ModelLayer.*;

import java.util.ArrayList;


/**
 * CustomerCtr functions as a controller for the CustomerCon and Customer classes in the ModelLayer.
 * Most changes to instances of those classes will go through this controller.
 * 
 * @author Jakob, Anna
 * @version 1.0
 */
public class CustomerCtr
{
    private CustomerCon customerCon;

    /**
     * Constructor for objects of class CustomerCtr
     */
    public CustomerCtr() {
        customerCon = CustomerCon.getInstance();
    }
    
    /**
     * Method for creating customer objects taking input parameters from the UI.
     * 
     * @param name          the name of the customer.
     * @param address       the address of the customer.
     * @param email         the email of the customer.
     * @param tlf           the telephonenumber of the customer.
     * 
     * @throws Exception    if the customer is already in the container.
     */
    public void createCustomer(String name, String address, String email, String tlf) throws Exception{
        Customer c = new Customer(name, address, email, tlf);
        customerCon.addCustomer(c);
    }
    /**
     * Method that gets a customer found by the customer number.
     * 
     * @param customerNo    takes an id-number.
     * 
     * @return              a customer object.
     */
    public Customer getCustomer(int customerNo){
        return customerCon.getCustomer(customerNo);
    }
    
    /**
     * A method to update the fields of a customer taking the input parameters from the UI.
     * 
     * @param customerNo        the unique number used to retreive the customer from the collection
     * @param newName           the updated customer name.
     * @param newAddress        the updated customer address.
     * @param newEmail          the updated customer email.
     * @param newTelefon        the updated customer phonenumber.
     */
    public void updateCustomer(int customerNo, String newName, String newAddress, String newEmail, String newTelefon){
        Customer c = getCustomer(customerNo);
        c.setName(newName);
        c.setAddress(newAddress);
        c.setEmail(newEmail);
        c.setTlf(newTelefon);
    }
    
    /**
     * A method to delete a Customer object.
     * 
     * @param customerNo        The id-number of a customer.
     */
    public void deleteCustomer(int customerNo){
        customerCon.deleteCustomer(customerNo);
    }
    
    /**
     * A method to return a customers list of offers.
     * 
     * @param customerNr        The id-number of the cusotmer.
     * 
     * @return                  A list of the customers offers.
     */
    public ArrayList<Order> getCustomerOffers(int customerNo) 
    {
        return getCustomer(customerNo).getOffers();
    }

  
}// end class CustomerCtr
